﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace AssemblyCYG
{
    public class ModbusTCP
    {
        public TcpClient clientSocket = new TcpClient();    //激光打标通讯
        public delegate void ReceiveInfoHandler(string receiveInfo);
        public event ReceiveInfoHandler receiveInfoHandler;
        public delegate void ReceiveInfoAutoHandler(int command);
        public event ReceiveInfoAutoHandler receiveInfoAutoHandler;

        int upCamAssembly_lastSig = 0;
        int downCamAssembly_lastSig = 0;
        int glue_lastSig = 0;
        int guide_lastSig = 0;
        int review_lastSig = 0;
        int scanCode_lastSig = 0;
        int plcReset_lastSig = 0;
        private object mLock = new object();
        public ModbusTCP()
        {
            //构造函数，开启接收信息线程
            StartReceiveInfoThread();
        }
        public bool ConnectServer(string ipAddress, int port)
        {
            try
            {
                if (!clientSocket.Connected)             //如果未处于连接
                {
                    clientSocket.Connect(ipAddress, port);              //连接服务器，端口号为服务器端提供,用于接收检测结果
                    if (!clientSocket.Connected)
                    {
                        return false;
                    }
                }

            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        public void CloseConnectServer()
        {
            try
            {
                if (clientSocket.Connected)
                {
                    clientSocket.Close();   //关闭连接
                    clientSocket = new TcpClient();
                }
            }
            catch (Exception ex)
            {

            }
        }
        public bool SendInfoToServer(string sendStr)
        {
            try
            {
                byte[] sendByte = Encoding.UTF8.GetBytes(sendStr);
                NetworkStream streamToServer = clientSocket.GetStream();
                streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器准备信号
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendPCErrorSignal(int order)
        {
            //发送pc异常信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x08;
                sendByte[9] = 0x02;

                sendByte[10] = 0x00;
                sendByte[11] = (byte)order;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        } 
        public bool ResetPhotoSignal(int order)
        {
            //重置拍照信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                switch (order)
                {
                    case 1:
                        sendByte[9] = 0xD0;
                        break;
                    case 2:
                        sendByte[9] = 0xD1;
                        break;
                    case 3:
                        sendByte[9] = 0xD2;
                        break;
                    case 4:
                        sendByte[9] = 0xD3;
                        break;
                    case 5:
                        sendByte[9] = 0xD4;
                        break;
                    case 6:
                        sendByte[9] = 0xD4;
                        break;
                }
                sendByte[10] = 0x00;
                sendByte[11] = 0x00;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendPhotoDownSignal(int order, int nflag)
        {
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                switch (order)
                {
                    case 1:
                        sendByte[9] = 0xDA;
                        break;
                    case 2:
                        sendByte[9] = 0xDB;
                        break;
                    case 3:
                        sendByte[9] = 0xDC;
                        break;
                    case 4:
                        sendByte[9] = 0xDD;
                        break;
                    case 5:
                        sendByte[9] = 0xDE;
                        break;
                    case 6:
                        sendByte[9] = 0xDE;
                        break;
                }
                sendByte[10] = 0x00;
                sendByte[11] = (byte)nflag;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        //--------------------------------------
        public void SendPCResetSignal(int index)
        {
            byte[] sendByte = new byte[12];
            sendByte[0] = 0x97;
            sendByte[1] = 0x96;
            sendByte[2] = 0x00;
            sendByte[3] = 0x00;
            sendByte[4] = 0x00;
            sendByte[5] = 0x06;
            sendByte[6] = 0x01;
            sendByte[7] = 0x06;
            sendByte[8] = 0x07;
            sendByte[9] = 0xD7;
            sendByte[10] = 0x00;
            sendByte[11] = (byte)index;
            lock (this.mLock)
            {
                NetworkStream streamToServer = clientSocket.GetStream();
                streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
            }
        }
        public bool RequestPhotoSignal()
        {
            //请求拍照信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x03;
                sendByte[8] = 0x07;
                sendByte[9] = 0xD0;
                sendByte[10] = 0x00;
                sendByte[11] = 0x08;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool NoticeRobotGuideMoveSignal(int index)
        {
            //通知机械手引导走位信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xE4;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)index;
                //if (isSuccess)
                //    sendByte[11] = 0x01;
                //else
                //    sendByte[11] = 0x02;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool RobotGuideJudgeProExist(int index)
        {
            //机械手引导判断有无料存在,0代表无料，1代表有料
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xDF;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)index;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SetRobotGuideCoor(int coor_X, int coor_Y)
        {
            //设置机械手引导坐标
            try
            {
                byte[] sendByte = new byte[21];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x0F;
                sendByte[6] = 0x01;
                sendByte[7] = 0x10;
                sendByte[8] = 0x07;
                sendByte[9] = 0xE6;
                sendByte[10] = 0x00;
                sendByte[11] = 0x04;
                sendByte[12] = 0x08;


                sendByte[15] = (byte)(coor_X >> 24);
                sendByte[16] = (byte)(coor_X >> 16);
                sendByte[13] = (byte)(coor_X >> 8);
                sendByte[14] = (byte)(coor_X);        //X坐标

                sendByte[19] = (byte)(coor_Y >> 24);
                sendByte[20] = (byte)(coor_Y >> 16);
                sendByte[17] = (byte)(coor_Y >> 8);
                sendByte[18] = (byte)(coor_Y);        //Y坐标
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool NoticeAssemblyMoveSignal(int order)
        {
            //通知装配走位信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xEE;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)order;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SetAssemblyOffsetCoor(int coor_X, int coor_Y, int phi)
        {
            //设置纠偏走位坐标
            try
            {
                byte[] sendByte = new byte[25];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x13;
                sendByte[6] = 0x01;
                sendByte[7] = 0x10;
                sendByte[8] = 0x07;
                sendByte[9] = 0xF0;
                sendByte[10] = 0x00;
                sendByte[11] = 0x06;
                sendByte[12] = 0x0C;

                sendByte[15] = (byte)(coor_X >> 24);
                sendByte[16] = (byte)(coor_X >> 16);
                sendByte[13] = (byte)(coor_X >> 8);
                sendByte[14] = (byte)(coor_X);        //X坐标

                sendByte[19] = (byte)(coor_Y >> 24);
                sendByte[20] = (byte)(coor_Y >> 16);
                sendByte[17] = (byte)(coor_Y >> 8);
                sendByte[18] = (byte)(coor_Y);        //Y坐标

                sendByte[23] = (byte)(phi >> 24);
                sendByte[24] = (byte)(phi >> 16);
                sendByte[21] = (byte)(phi >> 8);
                sendByte[22] = (byte)(phi);          //角度
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendReviewDetectResult(int result)
        {
            //发送自检结果
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xF8;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)result;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendPCReadySignal(int order)
        {
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x08;
                sendByte[9] = 0x04;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)order;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendScanCodeDownSignal(int order)
        {
            //发送扫码完成信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xDF;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)order;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendSiMoReusltSignal(int order)
        {
            //发送撕膜结果信号,1为成功，2为失败
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xF9;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)order;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendScanCodeResultSignal(int order)
        {
            //发送撕膜结果信号
            try
            {
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x06;
                sendByte[8] = 0x07;
                sendByte[9] = 0xFA;
                sendByte[10] = 0x00;
                sendByte[11] = (byte)order;
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SendScanCodeStr(string codeStr)
        {
            try
            {
                char[] codeChar = codeStr.ToArray();
                byte[] codeByte = Encoding.ASCII.GetBytes(codeChar, 0, codeChar.Length);
                byte[] sendByte = new byte[33];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x1B;
                sendByte[6] = 0x01;
                sendByte[7] = 0x10;
                sendByte[8] = 0x08;
                sendByte[9] = 0x16;        //寄存器地址2070   
                sendByte[10] = 0x00;
                sendByte[11] = 0x0A;       //寄存器数量10，2070-2079
                sendByte[12] = 0x14;

                for (int i = 0; i < codeByte.Length; i = i + 2)
                {
                    if (i < codeByte.Length-2)
                    {
                        sendByte[13 + i] = codeByte[i + 1];
                        sendByte[14 + i] = codeByte[i];
                    }
                    else
                    {
                        sendByte[14 + i] = codeByte[i];
                    }
                  
                }
                //for (int j = codeByte.Length; j < 20; j++)
                //{
                //    sendByte[codeByte.Length + j] = 0;
                //}
                lock (this.mLock)
                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void GetSNcodeFromPLC()
        {
            //通过plc获得SN码
            try
            {
                ShareData.strSNCode = "";
                byte[] sendByte = new byte[12];
                sendByte[0] = 0x97;
                sendByte[1] = 0x96;
                sendByte[2] = 0x00;
                sendByte[3] = 0x00;
                sendByte[4] = 0x00;
                sendByte[5] = 0x06;
                sendByte[6] = 0x01;
                sendByte[7] = 0x03;
                sendByte[8] = 0x08;
                sendByte[9] = 0x0C;
                sendByte[10] = 0x00;
                sendByte[11] = 0x0A;

                {
                    NetworkStream streamToServer = clientSocket.GetStream();
                    streamToServer.Write(sendByte, 0, sendByte.Length);     // 发往服务器信号
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void StartReceiveInfoThread()
        {
            Thread ReceiveTcpThread = new Thread(ReceiveTcpMessage);      //开启监听线程,接收检测结果
            ReceiveTcpThread.IsBackground = true;
            ReceiveTcpThread.Start();
        }
        private void ReceiveTcpMessage()
        {
            while (true)  //开始监听
            {
                try
                {
                    if (clientSocket.Connected)
                    {
                        NetworkStream streamToServer = clientSocket.GetStream();
                        byte[] receiveBuffer = new byte[1024];
                        int renum = streamToServer.Read(receiveBuffer, 0, receiveBuffer.Length);
                        if (renum > 0)
                        {
                            if (ShareData.projectItem == ShareData.ItemType.手动线组装)
                            {
                                string reiStr = Encoding.UTF8.GetString(receiveBuffer, 0, renum);
                                receiveInfoHandler(reiStr);       //绑定委托将接收到的信息传递出去
                            }
                            else
                            {
                                string reiStr = BitConverter.ToString(receiveBuffer, 0, renum);

                                if (reiStr.Contains("97-96-00-00-00-17-01-03") && reiStr.Length == 86)
                                {
                                    int length = reiStr.Length;
                                    for (int i = 0; i < 10; i++)
                                    {
                                        var tm = receiveBuffer[2 * i + 9];
                                        receiveBuffer[2 * i + 9] = receiveBuffer[2 * i + 10];
                                        receiveBuffer[2 * i + 10] = tm;
                                    }
                                    ShareData.strSNCode = Encoding.ASCII.GetString(receiveBuffer.Skip(9).Take(20).ToArray()).Replace("\0", "");
                                    if (ShareData.strSNCode == "")
                                        ShareData.strSNCode = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
                                }

                                if (reiStr.Contains("97-96-00-00-00-13-01-03") && reiStr.Length == 74)  //收到的拍照回复信号
                                {
                                    //拍照信号
                                    string glueStr = reiStr.Substring(30, 2);
                                    string guideStr = reiStr.Substring(36, 2);
                                    string upCamStr = reiStr.Substring(42, 2);
                                    string downCamStr = reiStr.Substring(48, 2);
                                    string reviewStr = reiStr.Substring(54, 2);
                                    string plcReadyCodeStr = reiStr.Substring(60, 2);
                                    string plcResetStr = reiStr.Substring(72, 2);
                                    //首先判断plc是否准备完成信号，02为自动，01为手动
                                    //if (ShareData.isRepet)
                                    //{
                                    //    if (plcReadyCodeStr != "01") continue;
                                    //}
                                    //else
                                    //{
                                    //    if (plcReadyCodeStr != "02") continue;
                                    //}
                                    //if (scanCodeStr == "00" && scanCode_lastSig == 1)
                                    //{
                                    //    scanCode_lastSig = 0;
                                    //}
                                    //else if (scanCodeStr == "01" && scanCode_lastSig == 0)
                                    //{
                                    //    //上相机对位拍照信号
                                    //    scanCode_lastSig = 1;
                                    //    receiveInfoAutoHandler(7);
                                    //}
                                    //收到PLC复位信号
                                    if (plcResetStr == "00" && plcReset_lastSig == 1)
                                    {
                                        plcReset_lastSig = 0;
                                    }
                                    else if (plcResetStr == "01" && plcReset_lastSig == 0)
                                    {
                                        //上相机对位拍照信号
                                        plcReset_lastSig = 1;
                                        receiveInfoAutoHandler(10);
                                        SendPCResetSignal(2);
                                    }

                                    if (glueStr == "00" && glue_lastSig == 1)
                                    {
                                        glue_lastSig = 0;
                                    }
                                    else if (glueStr == "01" && glue_lastSig == 0)
                                    {
                                        //收到胶形检测拍照信号
                                        glue_lastSig = 1;
                                        receiveInfoAutoHandler(1);
                                    }
                                    //guide_lastSig = 0;
                                    if (guideStr == "00" && guide_lastSig == 1)
                                    {
                                        guide_lastSig = 0;
                                    }
                                    else if (guideStr == "01" && guide_lastSig == 0)
                                    {
                                        //收到机械手引导信号
                                        guide_lastSig = 1;
                                        receiveInfoAutoHandler(2);
                                    }

                                    if (upCamStr == "00" && upCamAssembly_lastSig == 1)
                                    {
                                        upCamAssembly_lastSig = 0;
                                    }
                                    else if (upCamStr == "01" && upCamAssembly_lastSig == 0)
                                    {
                                        //上相机对位拍照信号，流道1
                                        upCamAssembly_lastSig = 1;
                                        receiveInfoAutoHandler(31);
                                    }
                                    else if (upCamStr == "02" && upCamAssembly_lastSig == 0)
                                    {
                                        //上相机对位拍照信号，流道2
                                        upCamAssembly_lastSig = 1;
                                        receiveInfoAutoHandler(32);
                                    }

                                    if (downCamStr == "00" && downCamAssembly_lastSig == 1)
                                    {
                                        downCamAssembly_lastSig = 0;
                                    }
                                    else if (downCamStr == "01" && downCamAssembly_lastSig == 0)
                                    {
                                        //下相机对位拍照信号
                                        downCamAssembly_lastSig = 1;
                                        receiveInfoAutoHandler(4);
                                    }
                                    else if (downCamStr == "02" && downCamAssembly_lastSig == 0)
                                    {
                                        //下相机判断撕膜是否成功信号
                                        downCamAssembly_lastSig = 1;
                                        receiveInfoAutoHandler(8);
                                    }

                                    if (reviewStr == "00" && review_lastSig == 2)
                                    {
                                        review_lastSig = 0;
                                    }
                                    else if (reviewStr == "01" && review_lastSig == 0)
                                    {
                                        //自检曝光1信号
                                        review_lastSig = 1;
                                        receiveInfoAutoHandler(5);
                                    }
                                    else if (reviewStr == "02" && review_lastSig == 1)
                                    {
                                        //自检曝光2信号
                                        review_lastSig = 2;
                                        receiveInfoAutoHandler(6);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {

                }
                Thread.Sleep(30);
            }
        }
    }
}
